package com.gwcloud.leetcode.offers;

import java.util.PriorityQueue;

/** 
* @ClassName   : Leetcode0590 
* @author      : ganwei 
* @date        : 2020年6月10日 
* @Description : TODO 
*/
public class Leetcode0590 {
	/**
	 * -解题思路，滑动窗口
	 */
	class Solution {
	    public int[] maxSlidingWindow(int[] nums, int k) {
	        if (nums == null || nums.length == 0 || k <= 0) {
	            return new int[0];
	        }

	        PriorityQueue<Integer> queue = new PriorityQueue<Integer>((a, b) -> b - a);
	        
	        for (int i = 0; i < k; i++){
	            queue.add(nums[i]);
	        }

	        int[] res = new int[nums.length - k + 1];
	        int j = 0;
	        res[j++] = queue.peek();

	        for (int i = k; i < nums.length; i++){
	            queue.remove(nums[i - k]);
	            queue.add(nums[i]);
	            res[j++] = queue.peek();
	        }

	        return res;
	    }
	}

    /**
     * -主函数
     */
    public static void main(String[] args) {
    	
    }
}
